import { observable, action } from "mobx";
import * as api from "../api/api";
import request from "../utils/request";
import { LoadHoc, loading } from '../hoc/loadHoc';

interface resRequest {
  totalCount: number,
  items: api.ArtPageOutput[]
}

export default class DynamicStore extends LoadHoc {
  // 获取动态列表
  @loading @action async getArticleList(params: {
      id:  string,
      pageIndex: number,
      pageSize: number,
    callback?: (res: resRequest) => void;
  }){
    const { id, pageIndex, pageSize, callback } = params;
    const res = await request(api.ArticleApiFetchParamCreactor.artclePagesByType({
      form: {
        id,
        skipCount:  (pageIndex-1)*pageSize,
        maxResultCount:pageSize
      }
    }));
    callback&&callback(res)
  }

  // 获取文章详情
  @loading @action async getArticleDetail(params: {
    form: { id: string },
    callback: (res: api.ArtPageOutput) => void
  }){
      const { form, callback } = params
      const res = await request(api.ArticleApiFetchParamCreactor.artDetails({
      form
    }));
    callback&&callback(res)
  }
}
